package a10_strategy;

import org.junit.Test;

public class Client {
	public static void main(String[] args) {
		// 当前环境来决定使用什么策略应对
		Context env = new Context();
		System.out.println("困难出现");
		System.out.println("想想应对策略");
		IStrategy fightstrategy = new FightStrategy();
		System.out.println("想好策略");
		env.setStrategy(fightstrategy);
		System.out.println("应对问题");
		env.handleProblem();

		System.out.println("困难又出现");
		System.out.println("想想应对策略");
		IStrategy escape = new EscapeStrategy();
		System.out.println("想好策略");
		env.setStrategy(escape);
		System.out.println("应对问题");
		env.handleProblem();
	}

	@Test
	public void lambdaStrategy() {
		// 当前环境来决定使用什么策略应对
		Context env = new Context();
		System.out.println("困难出现");
		System.out.println("想想应对策略");
		IStrategy s1 = () -> {
			System.out.println("不知道，先吃饭吧！");
		};
		System.out.println("想好策略");
		env.setStrategy(s1);
		System.out.println("应对问题");
		env.handleProblem();

	}
}
